using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BanHangCshap.Class;
namespace BanHangCshap
{
    public partial class frmTimKiemPhieuThuChi : DevExpress.XtraEditors.XtraForm
    {
        public frmTimKiemPhieuThuChi()
        {
            InitializeComponent();
        }
        KhachHangNCC clskhncc = new KhachHangNCC();
        PhieuThuChi clsthuchi = new PhieuThuChi();
        public delegate void GetDataTable(DataTable dt);
        public GetDataTable getDataTable;
        public string loaithuchi = "";
        public void loadKhachHangNCC()
        {
            DataTable dt = clskhncc.layDSTatCaKhachHangNCC();
            DataRow dr = dt.NewRow();
            dr[0] = "";
            dr[1] = " ";
            dr[2] = "";
            dt.Rows.InsertAt(dr, 0);
            glkuKHNCC3.Properties.DataSource = dt;
            glkuKHNCC3.Properties.ValueMember = "makhncc";
            glkuKHNCC3.Properties.DisplayMember = "makhncc";
            glkuKHNCC3.Properties.PopupFormWidth = 600;
            glkuvKHNCC3.BestFitColumns();
            glkuKHNCC4.Properties.DataSource = dt;
            glkuKHNCC4.Properties.ValueMember = "makhncc";
            glkuKHNCC4.Properties.DisplayMember = "tenkhncc";
            glkuKHNCC4.Properties.PopupFormWidth = 600;
            glkuvKHNCC4.BestFitColumns();
        }
        public void loadNhanVien()
        {
            NguoiDung clsnd = new NguoiDung();
            glkuNhanVien.Properties.DataSource = clsnd.layDSNguoiDung();
            glkuNhanVien.Properties.ValueMember = "tendn";
            glkuNhanVien.Properties.DisplayMember = "hoten";
            glkuNhanVien.Properties.PopupFormWidth = glkuNhanVien.Size.Width - 4;

        }
        private void frmTimKiemPhieuThuChi_Load(object sender, EventArgs e)
        {
            loadKhachHangNCC();
            loadNhanVien();
            dateTuNgay.EditValue = UltitityStatic.layNgayDauThang();
            dateDenNgay.EditValue = DateTime.Now;
        }

        

        private void glkuKHNCC3_EditValueChanged(object sender, EventArgs e)
        {
            glkuKHNCC4.EditValue = glkuKHNCC3.EditValue;
        }

        private void glkuKHNCC4_EditValueChanged(object sender, EventArgs e)
        {
            glkuKHNCC3.EditValue = glkuKHNCC4.EditValue;
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnDongY_Click(object sender, EventArgs e)
        {
            string tungay = "";
            string denngay = "";
            string makhncc = "";
            string tendn = "";
            try
            {
                tungay = ((DateTime)dateTuNgay.EditValue).ToString("dd/MM/yyyy");
            }
            catch (Exception)
            {

                tungay = "";
            }
            try
            {
                denngay = ((DateTime)dateDenNgay.EditValue).ToString("dd/MM/yyyy");
            }
            catch (Exception)
            {

                denngay = "";
            }
            try
            {
                makhncc = glkuKHNCC3.EditValue.ToString().Trim();
            }
            catch (Exception)
            {

                makhncc = "";
            }
            try
            {
                tendn = glkuNhanVien.EditValue.ToString().Trim();
            }
            catch (Exception)
            {

                tendn = "";
            }
            try
            {
                
                getDataTable(clsthuchi.timKiemPhieuThuChi(loaithuchi, tungay, denngay,makhncc, tendn));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());

            }
        }
    }
}